package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;
//    添加购物车
    @PostMapping("/add")
    public Result shoppingCartAdd(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.shoppingCartAdd(shoppingCartDTO);
        return Result.success();
    }

/*
 * @Description  查看购物车
 * @Param []
 * @return com.sky.result.Result<java.util.List<com.sky.entity.ShoppingCart>>
 **/
    @GetMapping("/list")
    public Result<List<ShoppingCart>> ShowShoppingCart(){
        List<ShoppingCart> list=shoppingCartService.showShoppingCart();
        return Result.success(list);
    }

    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }

    @PostMapping("/sub")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }
}
